package homework.homework1;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;

public class MouseEvent extends MouseAdapter {
    private MainJFrame mf;
    private Color c;

    public MouseEvent(MainJFrame mf){
        this.mf = mf;
        c = mf.getBackground();
    }

    // 鼠标进入
    @Override
    public void mouseEntered(java.awt.event.MouseEvent e) {
        JPanel p = (JPanel) e.getSource();
        mf.getContentPane().setBackground(p.getBackground());
    }

    // 鼠标移出
    @Override
    public void mouseExited(java.awt.event.MouseEvent e) {
        mf.getContentPane().setBackground(c);
    }

//    鼠标单击
    @Override
    public void mouseClicked(java.awt.event.MouseEvent e) {
        JPanel p = (JPanel) e.getSource();
        mf.getContentPane().setBackground(p.getBackground());
        this.c = p.getBackground();
    }
}
